/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.fvaz.demo.utils;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author felipe
 */
public class ConfigurationReader {
    
    protected static App app = new App();
    
    public static App getConfiguration(String path, String appName) {

        try {

            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setValidating(false);

            DefaultHandler handler = new AppHandler( appName);

            SAXParser parser = factory.newSAXParser();
            parser.parse(path, handler);
            

        } catch (IllegalArgumentException ex) {
            
            Logger.getLogger(ConfigurationReader.class.getName()).log(Level.SEVERE, null, ex);
            
        } catch (SecurityException ex) {
            
            Logger.getLogger(ConfigurationReader.class.getName()).log(Level.SEVERE, null, ex);
            
        } catch (IOException ex) {

            Logger.getLogger(ConfigurationReader.class.getName()).log(Level.SEVERE, null, ex);

        } catch (ParserConfigurationException ex) {

            Logger.getLogger(ConfigurationReader.class.getName()).log(Level.SEVERE, null, ex);

        } catch (SAXException ex) {

            Logger.getLogger(ConfigurationReader.class.getName()).log(Level.SEVERE, null, ex);

        }

        return app;

    }

}
